package com.wc.AlgoOJ_homework.AlgoOJ_test2.G_或出最大;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/8 21:15
 * @description http://43.138.190.70:8888/p/737?tid=65e6946827489dab814f88b8
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N];
    static int[] b = new int[N];
    static boolean[] vis = new boolean[N];
    static int t, n;

    // 思路，他变的位置最多是31个位置，也就是最多遍历31 * n 也就是 10^6的时间复杂度，管够
    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            Arrays.sort(a, 1, n + 1);
            b[1] = a[n];
            vis[n] = true;
            int maxN = b[1];
            int end = n + 1;
            for (int i = 2; i <= n; i++) {
                int idx = 0;
                // 取当前最大的
                int maxM = maxN;
                for (int j = 1; j <= n; j++) {
                    if (!vis[j] && (a[j] | maxN) > maxM) {
                        maxM = a[j] | maxN;
                        idx = j;
                    }
                }
                // 当没有数最大时候,后面就都一样的数字了,就可以break了
                if (maxM == maxN) {
                    end = i;
                    break;
                }
                maxN = maxM;
                b[i] = a[idx];
                vis[idx] = true;
            }
            for (int i = 1; i < end; i++) out.print(b[i] + " ");
            for (int i = 1; i <= n; i++) {
                if (!vis[i]) out.print(a[i] + " ");
            }
            out.println();
            Arrays.fill(vis, 1, n + 1, false);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
